package com.markovich.projects.netcoverage.services;

import android.content.Context;
import android.telephony.PhoneStateListener;
import android.telephony.ServiceState;
import android.telephony.SignalStrength;
import android.telephony.TelephonyManager;
import android.util.Log;

public class ConnectionService extends PhoneStateListener {

	public static boolean serviceAvailable = true;
	public static int currentSignalStrength = 0;
	private Context context;
	
	
	
	
	public ConnectionService(Context _context) {
		this.context = _context;
	}

	public void getServiceStrength() {
		
	}

	/**
	 * Valid Values between [0-31]
	 */
	public void onSignalStrengthsChanged(SignalStrength signalStrength) {
		Log.i("onSignalStrengthChanged()", "Signal Strength: "+signalStrength.getGsmSignalStrength());
		this.currentSignalStrength = signalStrength.getGsmSignalStrength();
	}

	public void getProviderInformation() {
		TelephonyManager telephonyManager = (TelephonyManager) this.context
				.getSystemService(Context.TELEPHONY_SERVICE);

		String simOperator = telephonyManager.getSimOperatorName();
		
		Log.i("getProviderInformation", "SimOperator = " + simOperator);

	}

	public void onServiceStateChanged(ServiceState serviceState) {
		super.onServiceStateChanged(serviceState);

		Log.i("onServiceStateChanged",
				"State integer = " + serviceState.getState());

		this.getProviderInformation();

		String phonestate;

		switch (serviceState.getState()) {
		case ServiceState.STATE_EMERGENCY_ONLY:
			phonestate = "STATE_EMERGENCY_ONLY";
			ConnectionService.serviceAvailable = true;
			break;
		case ServiceState.STATE_IN_SERVICE:
			phonestate = "STATE_IN_SERVICE";
			ConnectionService.serviceAvailable = true;
			break;
		case ServiceState.STATE_OUT_OF_SERVICE:
			phonestate = "STATE_OUT_OF_SERVICE";
			ConnectionService.serviceAvailable = false;
			break;
		case ServiceState.STATE_POWER_OFF:
			phonestate = "STATE_POWER_OFF";
			ConnectionService.serviceAvailable = false;
			break;
		default:
			phonestate = "Unknown";
			ConnectionService.serviceAvailable = true;
			break;
		}
		Log.i("updateServiceState", phonestate);
	}

}
